<?php
include '../mysqladmin.php';
$sno=$_GET["sNo"];
$name=$_GET["name"];
$sex=$_GET["sex"];
$class=$_GET["phone"];
$grade=$_GET["birth"];
$college=$_GET["email"];
$major=$_GET["address"];

//$major="计算机科学与技术";
$arr=Array("计算机科学与技术","网络工程","智能科学与技术","数据科学与大数据技术","空间信息与技术");
$isMajor=false;
for ($i=0;$i<count($arr);$i++){
    if($major==$arr[$i]) {
        $isMajor=true;
        break;
    }

}
if (!$isMajor){
    $code["msg"] = "没有此专业！";
    $res = json_encode($code);
    echo $res;
    exit();
}


//$stmt = $link->prepare("INSERT INTO student * VALUES (?, ?, ?, ?, ? , ?, ?)");
//$stmt->bind_param("isisiss", $sno, $name, $sex,$class,$great,$college,$major);
//$result=$stmt->execute();
$sql="INSERT INTO student (sno,`name` ,sex,class,grade,college,major) VALUES ({$sno}, '{$name}', {$sex}, '{$class}', {$grade} , '{$college}', '{$major}')";
$result= mysqli_query($link, $sql);
if($result){
    $code["status"] = true;
    $code["msg"] = "添加成功";
    $res = json_encode($code);
    echo $res;
}else{
    $code["msg"] = $link->error;
    $res = json_encode($code);
    echo $res;
}
mysqli_close($link);
?>